#include "dialogtargetcoordinates.h"
#include "ui_dialogtargetcoordinates.h"
#include <QMessageBox>

dialogTargetCoordinates::dialogTargetCoordinates(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::dialogTargetCoordinates)
{


    ui->setupUi(this);
    setWindowTitle("Enter World Coordinates For This Point");
    ui->lineEdit_WorldX->setFocus();
    ui->lineEdit_WorldX->setValidator(new QDoubleValidator(this));
    ui->lineEdit_WorldY->setValidator(new QDoubleValidator(this));
    ui->lineEdit_WorldZ->setValidator(new QDoubleValidator(this));

    connect(this, SIGNAL(accepted()), this, SLOT(verify()));

}

dialogTargetCoordinates::~dialogTargetCoordinates()
{
    delete ui;
}

void dialogTargetCoordinates::setUV(float u,float v)
{
    ui->lineEdit_uValue->setText(QString::number(u));
    ui->lineEdit_vValue->setText(QString::number(v));
}

void dialogTargetCoordinates::setXYZ(cv::Point3f World)
{
    //update Values
    WorldX=World.x; WorldY=World.y; WorldZ=World.z;
    //update Dialog Entries
    ui->lineEdit_WorldX->setText(QString::number(World.x));
    ui->lineEdit_WorldY->setText(QString::number(World.y));
    ui->lineEdit_WorldZ->setText(QString::number(World.z));

}


void dialogTargetCoordinates::on_lineEdit_WorldX_editingFinished()
{
    WorldX=ui->lineEdit_WorldX->text().toFloat();
}

void dialogTargetCoordinates::on_lineEdit_WorldY_editingFinished()
{
    WorldY=ui->lineEdit_WorldY->text().toFloat();
}

void dialogTargetCoordinates::on_lineEdit_WorldZ_editingFinished()
{
    WorldZ=ui->lineEdit_WorldZ->text().toFloat();
}

void dialogTargetCoordinates::verify() {
    if(!ui->lineEdit_WorldX->text().isEmpty() &&
       !ui->lineEdit_WorldY->text().isEmpty() &&
       !ui->lineEdit_WorldZ->text().isEmpty()) {
        //accept();
        return;
    }

    QMessageBox::StandardButton answer;
         answer = QMessageBox::warning(this, tr("Incomplete Coordinates"),
             tr("All coordinate values have not been entered.\n"
                "Do you want to discard this point?"),
             QMessageBox::Yes | QMessageBox::No);

         if (answer == QMessageBox::Yes)
             reject();
         else
           {} //need to go back to the edit

}

